package com.atguigu.tingshu.model.search;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.CompletionField;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.core.suggest.Completion;

@Data
@Document(indexName = "suggestinfo")
@JsonIgnoreProperties(ignoreUnknown = true)//目的：防止json字符串转成实体对象时因未识别字段报错
public class SuggestIndex {

    /**
     * 主键ID跟专辑索引库文档ID一致
     * 专辑上架->新增专辑文档到专辑索引库 同时 将专辑标题存入到提词索引库
     * 专辑上架->从专辑索引库删除专辑文档 同时 将提供索引库文档
     */
    @Id
    private String id;

    /**
     * 业务字段：存放原始内容，用于给用户提词结果展示数据
     * 原始内容：经典留声机
     */
    @Field(type = FieldType.Text, analyzer = "standard")
    private String title;

    /**
     * 提词检索字段用于汉字提词检索
     * 存储内容：["经典留声机"]
     */
    @CompletionField(analyzer = "standard", searchAnalyzer = "standard", maxInputLength = 20)
    private Completion keyword;

    /**
     * 提词检索字段用于拼音提词检索
     * 存储内容：["jingdianliushengji"]
     */
    @CompletionField(analyzer = "standard", searchAnalyzer = "standard", maxInputLength = 20)
    private Completion keywordPinyin;

    /**
     * 提词检索字段用于拼音首字母提词检索
     * 存储内容：["jdlsj"]
     */
    @CompletionField(analyzer = "standard", searchAnalyzer = "standard", maxInputLength = 20)
    private Completion keywordSequence;

}
